-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19631 - Improve error handling with null Persister in lazy loaded collections #10602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HHH-19631 - Improve error handling with null Persister in lazy loaded collections #10602
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrenaat This is good, but not quite enough. We get a similar NPE for:
parent.getChildren().iterator().next();
Also, the error message is a little too specific. I think the error could occur in other situations, e.g. whenever the collection is unreferenced.
2404953
to
29c6433
Compare
29c6433
to
2160996
Compare
Added that to tghe test
Tweaked the message a bit, let me know if it's better now. |
hibernate-core/src/test/java/org/hibernate/orm/test/events/PreDeleteEventListenerTest.java
Show resolved
Hide resolved
hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java
Outdated
Show resolved
Hide resolved
2160996
to
c8d4d06
Compare
public static void checkPersister(PersistentCollection collection, CollectionPersister persister) { | ||
if ( !collection.wasInitialized() && persister == null ) { | ||
((AbstractPersistentCollection) collection).throwLazyInitializationException( "collection is being removed" ); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this method really need to be static
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to add a default method to the PersistentCollection interface? Even if it's marked as @Internal
, it's still poorly justified i think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I was asking if it can be an instance method so that you don't need to pass in the PersistentCollection collection
and then cast it to AbstractPersistentCollection
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what i mean, if we don't add it to the super interface, we end up having to cast in DefaultInitializeCollectionEventListener
, not sure which is better, but now at least it's contained so to speak?
…collections Signed-off-by: Jan Schatteman <[email protected]>
Signed-off-by: Jan Schatteman <[email protected]>
c8d4d06
to
1c4384b
Compare
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.
https://hibernate.atlassian.net/browse/HHH-19631